package com.dmooo.yxmmerchant.fragment.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.common.dialog.ZDYDialog;
import com.common.dialog.ZDYTipDialog;
import com.common.glide.GlideUtils;
import com.common.mvpbase.BaseFragment;
import com.common.net.entity.SubjectPost;
import com.common.net.listener.HttpOnNextListener;
import com.common.net.subscribers.ProgressSubscriber;
import com.common.util.RecycleViewDivider;
import com.common.util.SPUtils;
import com.common.util.ScreenUtil;
import com.common.util.StartActivityUtil;
import com.common.util.ToastUtil;
import com.dmooo.yxmmerchant.R;
import com.dmooo.yxmmerchant.common.Config;
import com.dmooo.yxmmerchant.util.NotificationUtil;
import com.dmooo.yxmmerchant.view.ui.ChangeAccountActivity;
import com.dmooo.yxmmerchant.view.ui.LoginActivity;
import com.suke.widget.SwitchButton;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class MineFragment extends BaseFragment {
    Unbinder unbinder;
    private boolean isFirstVisible = true;
    private static MineFragment indexFragment;
    private ZDYDialog zdyDialog;
    private ZDYTipDialog zdyTipDialog;
    private boolean isOpen=false;
    private SwitchButton sb_check;

    public static MineFragment getInstance() {
        if (indexFragment == null) {
            synchronized (MineFragment.class) {
                indexFragment = new MineFragment();
            }
        }
        return indexFragment;
    }

    @Override
    public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_mine, null);
        unbinder = ButterKnife.bind(this, view);
        sb_check=view.findViewById(R.id.sb_check);
        initListener();
        return view;
    }

    private void initListener() {
        sb_check.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (isChecked) {
                    if (!NotificationUtil.isNotificationEnabled(getActivity())) {
                        NotificationUtil.OpenNotificationSetting(getActivity(), new NotificationUtil.OnNextLitener() {
                            @Override
                            public void onNext() {

                            }
                        });
                    } else {
                        SPUtils.put(getActivity(), Config.IS_USER_OPEN_INFORM, "1");
                    }
                } else {
                    SPUtils.put(getActivity(), Config.IS_USER_OPEN_INFORM, "0");
                }
            }
        });
    }

    @Override
    public void initPresenter() {
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            if (isFirstVisible) {
                isFirstVisible = false;
            }
        }
    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void errorMsg(String msg) {
    }

    @Override
    protected void lazyload() {
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @OnClick({R.id.txt_exit,R.id.changeAccount_tv})
    public void onViewClicked(View view) {
        Bundle bundle = new Bundle();
        Intent intent;
        switch (view.getId()) {
            case R.id.txt_exit:
                intent=new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
                getActivity().finish();
                break;
            case R.id.changeAccount_tv:
                intent=new Intent(getActivity(), ChangeAccountActivity.class);
                startActivity(intent);
//                getActivity().finish();
//                getActivity().finish();
                break;


        }
    }
}
